<template>
  <div>
    <div class="header">
      <div class="head-back">
        <div class="w">
          <i class="el-icon-back" @click="back()">&nbsp;课程中心</i>
        </div>
      </div>
    </div>
    <div class="content">
      <div class="w">
        <div class="user-info">
            <h1>个人信息</h1>
            <ul>
              <li>
                头像：
                <span class="user-avatar">
                  <img src="@/assets/images/2.jpg" alt="">
                </span>
              </li>
              <li>
                账号：<span>12334455</span>
              </li>
              <li>
                昵称：<span>qsbc</span>
              </li>
              <li>
                性别：<span>男</span>
              </li>
              <li>
                邮箱：<span>751156604@qq.com</span>
              </li>
              <li>
                电话：<span>1122221231241</span>
              </li>
              <li>
                班级：<span>信管201</span>
              </li>
              <li>
                <el-button type="text" @click="dialogVisibleOne = true">修改个人信息</el-button>
                <el-button type="text" @click="dialogVisibleTwo = true">更改密码</el-button>
              </li>
            </ul>

<!--          修改个人信息弹框 start-->
          <el-dialog
              title="修改信息"
              :visible.sync="dialogVisibleOne"
              width="30%"
              :before-close="handleClose">
            <el-form  label-width="80px" size="small">
              <el-form-item label="上传头像">
                <el-upload
                    class="avatar-uploader"
                    action="https://jsonplaceholder.typicode.com/posts/"
                    :show-file-list="false"
                    :on-success="handleAvatarSuccess"
                    :before-upload="beforeAvatarUpload">
                  <img v-if="imageUrl" :src="imageUrl" class="avatar">
                  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload>
              </el-form-item>

              <el-form-item label="昵称">
                <el-input v-model="Sname"/>
              </el-form-item>

              <el-form-item label="性别">
                <el-radio-group v-model="isMan">
                  <el-radio :label="1">男&nbsp;&nbsp;&nbsp;&nbsp;</el-radio>
                  <el-radio :label="0">女</el-radio>
                </el-radio-group>
              </el-form-item>

              <el-form-item label="邮箱">
                <el-input v-model="email" />
              </el-form-item>

              <el-form-item label="电话">
                <el-input v-model="tel" />
              </el-form-item>
            </el-form>

            <span slot="footer" class="dialog-footer">
              <el-button @click="dialogVisibleOne = false">取 消</el-button>
              <el-button type="text" @click="dialogVisibleOne = false">确 定</el-button>
            </span>
          </el-dialog>
<!--          修改个人信息弹框 end-->
<!--          修改密码弹框 start-->
          <el-dialog
              title="修改密码"
              :visible.sync="dialogVisibleTwo"
              width="30%"
              :before-close="handleClose">
            <el-form  label-width="130px" size="small">
              <el-form-item label="旧密码">
                <el-input placeholder="请输入密码" v-model="oldPassword" show-password></el-input>
              </el-form-item>
              <el-form-item label="新密码">
                <el-input placeholder="请输入密码" v-model="newPassword" show-password></el-input>
              </el-form-item>
            </el-form>

            <span slot="footer" class="dialog-footer">
              <el-button @click="dialogVisibleTwo = false">取 消</el-button>
              <el-button type="text" @click="dialogVisibleTwo = false">确 定</el-button>
            </span>
          </el-dialog>
<!--          修改密码弹框 start-->

        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  components: {
  },
  data() {
    return {
      dialogVisibleOne: false,
      dialogVisibleTwo: false,
      Sname: 'huang',
      imageUrl: '',
      isMan: 1,
      email: '751156604@qq.com',
      tel: '1122221231241',
      oldPassword: '',
      newPassword: '',
    };
  },
  created() {
  },
  methods: {
    back() {
      this.$router.push('/user');
    },
    // 修改个人信息弹框关闭提示
    handleClose(done) {
      this.$confirm('确认关闭？')
          .then(_ => {
            done();
          })
          .catch(_ => {});
    },
    // 上传头像的相关方法
    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === 'image/jpeg';
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.$message.error('上传头像图片只能是 JPG 格式!');
      }
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!');
      }
      return isJPG && isLt2M;
    }
  },
  watch: {},
};
</script>
<style src="@/assets/css/userInfo.css"  scoped></style>
<style>
@import "@/assets/css/base.css";
/*上传头像框样式*/
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 50%;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 100px;
  height: 100px;
  line-height: 100px;
  text-align: center;
}
.avatar {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  display: block;
}
</style>